﻿using Kaskelot.SP.Core;
using Stockholm.SOA.Kaskelot.WCF.DataContracts;
using Stockholm.SOA.Kaskelot.WCF.FaultContracts;
using Stockholm.SOA.Kaskelot.WCF.ServiceContracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;

namespace Kaskelot.SP.Services
{
	public class ValService : BaseService<IKaskelotService>
	{
		public Val GetVal(Guid? id)
		{
			Val val = null;
			try
			{
				val = this.channel.GetVal(id);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "GetVal", string.Format("Error getting val with id {0}", id.ToString()), ex);
			}
			return val;
		}

		public void UpdateVal(Val val, bool skipWriteCheck = false)
		{
			if(!skipWriteCheck)
				base.CheckWriteAllowed();

			try
			{
				this.channel.UpdateVal(val);
			}
			catch (FaultException<ErrorInformation> ex)
			{
				Logger.LogError(this, LayerNames.Services, "UpdateVal", "Error updating val", ex);
				throw;
			}
		}
	}
}
